﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Xml;
using Common.Utilities.Dispatcher;
using Workflows.Components.TextMining.Properties;

namespace Workflows.Components.TextMining.FullTextSearch
{
	/// <summary>
	/// 
	/// </summary>
	[Serializable]
	public class SqlFullTextSearchComponent:WorkflowComponentBase
	{
		#region ctor
		/// <summary>
		/// 
		/// </summary>
		public SqlFullTextSearchComponent()
			: base()
		{
			this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
			this.ComponentCategory = WorkflowComponentCategory.TextMining.ToString();
			this.ComponentName = "Fulltext search";
			this.Description = "Search text using sql server full text feature";
			this.ComponentIcon = Resources.vdt80pui_1050;
			this.ComponentImage = Resources.SqlWb_10008;

			this._Instruction =
				new SqlFullTextSearchInstruction(this.ComponentID, Guid.Empty,
					string.Empty,string.Empty, string.Empty, string.Empty,string.Empty,
					string.Empty,new Dictionary<string, double>(), new List<string>());
			this._Output =
				new SqlFullTextSearchOutput(this.ComponentID, Guid.Empty,
				                            string.Empty, 0, 0, 0, new TimeSpan(0, 0, 0, 0));
		}
		#endregion

		#region Overrides of WorkflowComponentBase

		private SqlFullTextSearchInstruction _Instruction;
		/// <summary>an object that encapsulate instruction settings.</summary>
        public override InstructionBase Instruction
		{
			get { return _Instruction; }
			set { _Instruction = (SqlFullTextSearchInstruction) value; }
		}

		private SqlFullTextSearchOutput _Output;
		/// <summary>an object to encapsulate output</summary>
        public override ResultBase Output
		{
			get { return _Output; }
			set { _Output=(SqlFullTextSearchOutput) value; }
		}

        /// <summary></summary>
        public string ConnStr
        {
            get
            {
                return this._Instruction.ConnStr;
            }
            set
            {
                this._Instruction.ConnStr = value;
            }
        }

        /// <summary></summary>
        public string SearchResultFilePath
        {
            get
            {
                return this._Instruction.SearchResultFilePath;
            }
            set
            {
                this._Instruction.SearchResultFilePath = value;
            }
        }
		#endregion

		public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
		{
			XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
			this.Instruction.Serialize(ref xDoc, ref xNode);
			return xNode;
		}

		public override WorkflowComponentBase Instantiate(XmlNode xNode)
		{
			SqlFullTextSearchComponent component = (SqlFullTextSearchComponent)base.Instantiate(xNode);
			component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
			return component;
		}
	}
}
